package Login

import (
	"MedicalTreatment/global"
	"MedicalTreatment/model"
	"github.com/gin-gonic/gin"
)

func Loginuser(r *gin.Engine) {
	r.POST("/login", func(context *gin.Context) {
		var user model.RegisterText
		if err := context.ShouldBindJSON(&user); err != nil {
			context.JSON(200, gin.H{
				"Msg": err,
			})
			return
		}
		count := global.DB.Model(&model.RegisterText{}).Where("user_name = ? AND password = ?", user.Username, user.Password).First(&user).RowsAffected
		if count != 0 {
			context.JSON(200, gin.H{
				"Msg": "登录成功",
			})

		} else {
			context.JSON(2000, gin.H{
				"Msg": "登录失败",
			})
		}
	})
}
